﻿using BillHelper.Properties;
using DemoForBillOcr;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Management;
using System.Windows.Documents;
using System.Windows.Forms;
using TaxAssistantBase;
using WindowsFormsApp2;
namespace BillHelper
{
    public partial class AdminJM : Form
    {
        public AdminJM()
        {
            InitializeComponent();
        }
        //0.声明自适应类实例  
        //AutoAdaptWindowsSize autoAdaptSize;
        //1.所有票据数据 
        private IList<InvoiiceOcrModel> currentPiaoJuList;
        //1.销项票据数据 
        private IList<InvoiiceOcrModel> currentXiaoXiangPiaoJuList;
    
        //2.查询条件-文本框
        private string currentSeachText;
        //3.票据类型
        private int currentSeachPiaoJuType = -100;
        //4.征期
        private string currentDeclareDate;
        //5.当前的公司名称
        private string currentCompanyName;
        //6.当前的公司税号
        private string currentCompanyTaxNum;
        //总数据
        private List<InvoiiceOcrModel> bpmlist;
        // 年份
        private string NowYear;
        //按钮按下
        private string ButtonDown;
        //按下
        private string ButtonDowns;
        //类别按钮
        private Button[] btnsType;
        //售方和收放按钮
        private Button[] btnsTypeXS;
        //读取状态集合
        private PictureBox[] pbox;
        //删除图标
        private PictureBox[] delepbox;
        //公司库
        private List<BatchInfo> companyAll;
        //采购方标识
        private string CaiGouFang = "";
        //代开标识
        private string DaiKaiBiaoShi = "";
        //统计标识
        private string TongJiBiaoShi = "";
        //销售方标识
        private string XiaoShouFang = "";
        //当前时间
        private string todayPiaoJuTime = DateTime.Now.ToString("yyyyMMdd");
        //进程
        private Process prosses;
        private bool isnPross;
        //图片id
        private int imgid;
        //1.当前选中票据数据 
        private IList<InvoiceSonModel> currentXuanZhongPiaoJuList;
        //1.当前选中票据明细数据 
        private IList<invoiceOcrDetailed> currentXuanZhongPiaoJuMingXiList = new List<invoiceOcrDetailed>();
        //传模态框明细list
        private IList<invoiceOcrDetailed> dclist = new List<invoiceOcrDetailed>();
        private BindingList<DetailContent> zhikong = new BindingList<DetailContent>();
        private CompGroup cg;
        private string todaytime = "";
        private IList<InvoiiceOcrModel> zuizhongList;
        private List<HighSpeedRailTicket> hsrtTableList;
        private int zhuanhuannum = 0;
        private int showImgNum = 9;
        private int xunHuanNum = 0;
        private IList<invoiceOcrDetailed> dclist1 = new List<invoiceOcrDetailed>();
        private IList<InvoiceOcrTaxtjtableMx> currentcliicktongjitabledata = new List<InvoiceOcrTaxtjtableMx>();
        private IList<InvoiceOcrTaxtjtable> currentclickTableMain = new List<InvoiceOcrTaxtjtable>();
        //统计表
        private List<InvoiceOcrTaxtjtable> iotable;
        //1.xiaoshou票据数据 
        private IList<InvoiiceOcrModel> currentXaioFShouFPiaoJuList;
        private IList<string> imglists = new List<string>();
        InvoiiceOcrModel imgclickedinfo = new InvoiiceOcrModel();
        ImageList imglistec = new ImageList();
        private HeadJinDuTiao jdt = new HeadJinDuTiao();
        WsdLogger wlog = new WsdLogger("GuanLiLog");
        public AdminJM(HeadJinDuTiao jdt)
        {
            this.jdt = jdt;
            InitializeComponent();
        }
        //初始化
        private void Form6_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            ClearDate();
            clearInvoiceInfo();
            CompanyNameEnd.Select();
            uploadeSucc.Visible = false;
            btnsTypeXS = new Button[] { XiaoShou, CaiGou, FeiQiBill, DaiKai,tongji};
            pbox = new PictureBox[] { readstate1, readstate2, readstate3, readstate4, readstate5, readstate6, readstate7, readstate8, readstate9 };
            delepbox = new PictureBox[] { close1, close2, close3, close4, close5, close6, close7, close8, close9 };
            hidenTuBiao();
            NowYear = DateTime.Now.ToString("yyyy");
            string apiurl = ApiUrlList.DECLARYDATE;//获取征期
            string temp = "";
            string date;
            string delaredate;
            try
            {
                var result = RestOrcTool.Post(out temp, new InvoiiceOcrModel(), apiurl);
                date = Convert.ToString(result);
                delaredate = date.Split(':')[1].Replace("\"", "");
                currentDeclareDate = delaredate;
            }
            catch (Exception ex)
            {
                wlog.Write(ex.Message);
                return;
            }
            Button bt = new Button();
            bt.Tag = delaredate.Substring(4, 2);
            bt.Text = delaredate.Substring(4, 2);
          //  btnZhengqi1_Click(bt, new EventArgs());
            xiaofangnum.Text = "0";
            caigounum.Text = "0";
            FeiQiNum.Text = "0";
            daikainum.Text = "0";
            tongjinum.Text = "0";
            currentXaioFShouFPiaoJuList = null;
            ButtonDowns = "转换";
            AdminJM_SizeChanged(sender, e);
        }
        private void twoBuffer()
        {
            foreach (PictureBox p in pbox)
            {
                p.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance
        | System.Reflection.BindingFlags.NonPublic).SetValue(p, true, null);
            }
            foreach (PictureBox dp in delepbox)
            {
                dp.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance
       | System.Reflection.BindingFlags.NonPublic).SetValue(dp, true, null);
            }
        }
        //月分行点击事件
        private void btnZhengqi1_Click(object sender, EventArgs e)
        {
            var btns = sender as Button;
            string declareDate = Convert.ToString(btns.Tag);
            string dd = NowYear + declareDate;
            //1.设置征期
            currentDeclareDate = dd;
            //1.获取票据详情数据
            ButtonDowns = "转换";
        }
        //绑定公司
        public void fuzhiCompanyName(string fuzhicompanyName, string cdaddtime, List<InvoiiceOcrModel> currentPiaoJu, CompGroup cgp, bool isnPross, Process pross,List<HighSpeedRailTicket> hsrtTableList)
        {
            wlog.Write("显示传参数 fuzhicompanyName：" + fuzhicompanyName + "cdaddtime:" + cdaddtime + "currentPiaoJu数量" + currentPiaoJu.Count);
            this.isnPross = isnPross;
            prosses = pross;
            this.hsrtTableList = hsrtTableList;
            CompanyNameEnd.Text = fuzhicompanyName;
            currentCompanyName = fuzhicompanyName;
            currentPiaoJuList = currentPiaoJu;
            todaytime = cdaddtime;
            allbutenhuifu();
            CaiGouFang = "";
            DaiKaiBiaoShi = "";
            TongJiBiaoShi = "";
            XiaoShouFang = "";
            cg = cgp;
            currentXaioFShouFPiaoJuList = null;
            ButtonDowns = "转换";
            ButtonDown = null;
            currentSeachPiaoJuType = -100;
            zhuanhuannum = 0;
            showImgNum = 9;
            xunHuanNum = 0;
            PicNum.Text = "0";
            tongjinum.Text = "0";
            setkongjianWith();
            CompanyNameEnd.Select();
            companysx_CellClick();
            firstHsrtInfo();
        }
        private void firstHsrtInfo() {
            if (hsrtTableList.Count>0) {
                setHSRTList(hsrtTableList[0]);
            }
            else{
                HighSpeedRailTicket hstk = new HighSpeedRailTicket();
                setHSRTList(hstk);
            }
           
        }
        private void setHSRTList(HighSpeedRailTicket hsrt)
        {
            if (hsrt != null)
            {
                startStation.Text = hsrt.startStation;
                trainNumber.Text = hsrt.trainNumber;
                endStation.Text = hsrt.endStation;
                startDate.Text = hsrt.startDate;
                startTime.Text = hsrt.startTime;
                seat.Text = hsrt.seat;
                ticketPrice.Text = hsrt.ticketPrice;
                searType.Text = hsrt.searType;
                name.Text = hsrt.name;
                idNumber.Text = hsrt.idNumber;
                number.Text = hsrt.number;
            }
            else
            {
                startStation.Text = "";
                trainNumber.Text = "";
                endStation.Text = "";
                startDate.Text = "";
                startTime.Text = "";
                seat.Text = "";
                ticketPrice.Text = "";
                searType.Text = "";
                name.Text = "";
                idNumber.Text = "";
                number.Text = "";
            }

        }
        private void getmoney(decimal money, decimal taxmoney,ref decimal moneyhj,ref decimal taxmoneyhj) {
            moneyhj += money;
            taxmoneyhj += taxmoney;
        }

        
        //得到筛选征期后的数据
        private List<InvoiiceOcrModel> chuliPiaoJu(string declaredate)
        {
            List<InvoiiceOcrModel> bplist = new List<InvoiiceOcrModel>();
            if (bpmlist.Count > 0)
            {
                foreach (InvoiiceOcrModel bp in bpmlist)
                {
                    if (declaredate == bp.declaredate)
                    {
                        bplist.Add(bp);
                    }
                }
            }
            return bplist;
        }
        //公司点击事件
        private void companysx_CellClick()
        {
            ButtonDowns = "转换";
            //设置公司名称
            CompanyNameBT.Text = CompanyNameEnd.Text;
            //2.查找匹配的详情
            BindPiaoJuList();
        }
        //高铁票
        private void PaioJuType_Click(object sender, EventArgs e)
        {
            var btn = sender as Button;
            currentXaioFShouFPiaoJuList = null;
            xunHuanNum = 0;
            if (Convert.ToString(btn.Tag) != ButtonDown)
            {
                PicNum.Text = "0";
                ButtonDowns = "按下";
                ButtonDown = Convert.ToString(btn.Tag);
                SetPiaoJuTypeBtnColor(btn);
                try
                {
                    if (Convert.ToString(btn.Tag) == "-1")
                    {
                        currentSeachPiaoJuType = int.Parse(Convert.ToString(btn.Tag));
                        CaiGouFang = "";
                        XiaoShouFang = "";
                        DaiKaiBiaoShi = "";
                        TongJiBiaoShi = "";
                        setkongjianWith();
                    }
                    else if (Convert.ToString(btn.Tag) == "-2")
                    {
                        XiaoShouFang = "";
                        TongJiBiaoShi = "";
                        currentSeachPiaoJuType = -100;
                        DaiKaiBiaoShi = "";
                        CaiGouFang = "采购方";
                        setkongjianWith();
                    }
                    else if (Convert.ToString(btn.Tag) == "-3")
                    {
                        XiaoShouFang = "销售方";
                        CaiGouFang = "";
                        TongJiBiaoShi = "";
                        DaiKaiBiaoShi = "";
                        currentSeachPiaoJuType = -100;
                        setkongjianWith();
                    }
                    else if (Convert.ToString(btn.Tag) == "10")
                    {
                        DaiKaiBiaoShi = "代开";
                        XiaoShouFang = "";
                        CaiGouFang = "";
                        TongJiBiaoShi = "";
                        currentSeachPiaoJuType = -100;
                        setkongjianWith();
                    }
                    else if (Convert.ToString(btn.Tag) == "100")
                    {
                        TongJiBiaoShi = "高铁票";
                        XiaoShouFang = "";
                        CaiGouFang = "";
                        DaiKaiBiaoShi = "";
                        currentSeachPiaoJuType = 100;
                        imgNum.Visible = false;
                        imageinfo.Visible = false;
                        gtTable.Visible = true;
                    }
                }
                catch (Exception ex)
                {
                    wlog.Write(ex.Message);
                }
                ButtonDown = Convert.ToString(btn.Tag);
                xunHuanNum = 0;
                BindPiaoJuList();
            }
            else if (Convert.ToString(btn.Tag) == ButtonDown)
            {
                setkongjianWith();
                btn.BackColor = Color.MintCream;
                currentSeachPiaoJuType = -100;
                ButtonDown = null;
                XiaoShouFang = "";
                CaiGouFang = "";
                DaiKaiBiaoShi = "";
                TongJiBiaoShi = "";
                BindPiaoJuList();
            }
            //票据类型
            //设置票据类型
            //调用绑定方法
        }

        private void setkongjianWith()
        {
            imgNum.Visible = true;
            imageinfo.Visible = true;
            gtTable.Visible = false;
        }

        //绑定票据数据
        private void BindPiaoJuList()
        {
            IList<InvoiiceOcrModel> bpmlist = new List<InvoiiceOcrModel>();
            IList<InvoiiceOcrModel> bpmlist1 = new List<InvoiiceOcrModel>();
            IList<InvoiiceOcrModel> tempZhuanHuan = new List<InvoiiceOcrModel>();
            List<HighSpeedRailTicket> hsrtlist = new List<HighSpeedRailTicket>();
            hidenTuBiao();
            zuizhongList = new List<InvoiiceOcrModel>();
            if (currentCompanyName == "未识别票据")
            {
                currentCompanyName = null;
            }
            clearInvoiceInfo();
            if (CaiGouFang == "采购方")
            {
                wlog.Write("进入采购方");
                CaiGouXiaoShouShaiXuan("购方企业名称", "购方纳税号");
                hsrtlist = new List<HighSpeedRailTicket>();
            }
            else if (XiaoShouFang == "销售方")
            {
                wlog.Write("进入销售方");
                CaiGouXiaoShouShaiXuan("销方企业名称", "销方纳税号");
                hsrtlist = new List<HighSpeedRailTicket>();
            }
            else if (DaiKaiBiaoShi == "代开")
            {
                wlog.Write("代开");
                CaiGouXiaoShouShaiXuan("代开", "");
                hsrtlist = new List<HighSpeedRailTicket>();
            } else if (TongJiBiaoShi== "高铁票") {
                if (hsrtTableList != null) {
                    if (hsrtTableList.Count>0) {
                        hsrtlist = hsrtTableList;
                        tongjinum.Text =Convert.ToString(hsrtTableList.Count);
                        firstHsrtInfo();
                    }
                }

            }
            if (currentXaioFShouFPiaoJuList != null)
            {
                tempZhuanHuan = currentXaioFShouFPiaoJuList;
            }
            else
            {
                tempZhuanHuan = currentPiaoJuList;
            }
            string mac = "";
            try
            {
                //获取mac
                mac = getMac();
                wlog.Write("获取电脑MAC地址:" + mac);
            }
            catch (Exception ex)
            {
                wlog.Write("获取电脑MAC地址报错" + ex.Message);
            }
            //筛选，公司名称，票据类型
            if (currentSeachPiaoJuType == -100)
            {
                var piaojulist = from endPiaoJuInfo in tempZhuanHuan where endPiaoJuInfo.declaredate == currentDeclareDate && endPiaoJuInfo.companyName == currentCompanyName && endPiaoJuInfo.mac == mac && endPiaoJuInfo.todaytime == todaytime select endPiaoJuInfo;

                bpmlist = piaojulist.ToList();
            } 
            else
            {
                var piaojulist2 = from endPiaoJuInfo in tempZhuanHuan where endPiaoJuInfo.declaredate == currentDeclareDate && endPiaoJuInfo.companyName == currentCompanyName && endPiaoJuInfo.billtype == currentSeachPiaoJuType && endPiaoJuInfo.mac == mac && endPiaoJuInfo.todaytime == todaytime select endPiaoJuInfo;
                bpmlist = piaojulist2.ToList();
            }
            var piaojulist3 = from endPiaoJuInfo in currentPiaoJuList
                              where endPiaoJuInfo.declaredate == currentDeclareDate && endPiaoJuInfo.companyName == currentCompanyName && endPiaoJuInfo.mac == mac && endPiaoJuInfo.todaytime == todaytime
                              select endPiaoJuInfo;
            bpmlist1 = piaojulist3.ToList();
            if (bpmlist.Count > 9|| hsrtTableList.Count>9)
            {
                showImgNum = 9;
                leftbtn.Enabled = true;
                leftbtn.BackgroundImage = Resources.leftbutton;
            }
            else
            {
                if (bpmlist.Count > 0)
                {
                    showImgNum = bpmlist.Count;
                }
                else {
                    showImgNum = hsrtTableList.Count;
                }
               
                rightbtn.Enabled = false;
                rightbtn.BackgroundImage = Resources.rightbuttonNoDian;
                leftbtn.Enabled = false;
                leftbtn.BackgroundImage = Resources.leftbuttonNoDian;
            }
            wlog.Write("绑定数据后" + bpmlist);
            if (bpmlist.Count == 0)
            {
                PicNum.Text = "0";
            }
            if (hsrtlist.Count > 0)
            {
                imgBindList(new List<InvoiiceOcrModel>(), hsrtlist);
            //    zuizhongTongJiTableList = iotableser;
            }
            else {
                imgBindList(bpmlist, new List<HighSpeedRailTicket>());
            }
            zuizhongList = bpmlist;
            first();//绑定图片
            BindingList<InvoiiceOcrModel> bplists = new BindingList<InvoiiceOcrModel>(bpmlist);
            if (ButtonDowns == "转换")
            {
                piaoJuNum(bpmlist1);//票据数
                piaojuXFSFNum(bpmlist1);
                if (iotable != null)
                {
                    if (iotable.Count > 0)
                    {
                        tongjinum.Text = Convert.ToString(iotable.Count); 
                    }
                }
            }
            issucctj();
        }
        public void issucctj() {
            if (iotable != null)
            {
                if (iotable.Count > 0)
                {
                    int tongjinnum = 0;
                    for (int i = 0; i < iotable.Count; i++)
                    {
                        if (iotable[i].successduijie == "0")
                        {
                            tongjinnum++;
                        }
                    }
                }
            }
        }
        //绑定图片
        private void imgBindList(IList<InvoiiceOcrModel> bpmlist,List<HighSpeedRailTicket> hsrtlist)
        {
            uploadeSucc.Hide();
            ReadState.BackgroundImage = null;
            int imgnum = 1;
            List<string> imglists1 = new List<string>();
            imglists = new List<string>();
            taxImage.ImageLocation = null;
            imgView.LargeImageList = new ImageList();
            imgView.Items.Clear();
            imgView.Refresh();
            int j = xunHuanNum;
            string year = currentDeclareDate.Substring(0, 4);
            string month = currentDeclareDate.Substring(4, 2);
            var dd = AppDomain.CurrentDomain.BaseDirectory;
            string activeDir = dd;
            string newPath = Path.Combine(activeDir, "SaoMiaoShiB\\HandleWenJ\\" + todayPiaoJuTime);
            if (bpmlist.Count > 0)
            {
                var imglist = from imgList in bpmlist select imgList.imgUrl;
                imglists1 = imglist.ToList();
                if (imglists1.Count > 0)
                {
                    for (j = xunHuanNum; j < showImgNum; j++)
                    {
                        foreach (InvoiiceOcrModel bpms in bpmlist)
                        {
                            if (bpms.imgUrl == imglists1[j])
                            {
                                readStateFuZhi(bpms, imgnum);
                                break;
                            }
                        }
                        string[] img = imglists1[j].Split('/');
                        if (img.Length >= 2)
                        {
                            string imgName = img[img.Length - 1];
                            string batchid = "";
                            if (imgName.Split('_').Length > 1)
                            {
                                batchid = imgName.Split('_')[1];
                            }
                            imglists.Add(newPath + "\\" + batchid + "\\" + imgName);
                        }
                        imgnum++;
                    }
                }
                FileStream fs = null;
                imglistec = new ImageList();
                if (imglists.Count > 0)
                {
                    imglistec.ImageSize = new Size(100, 90);
                    for (int i = 0; i < imglists.Count; i++)
                    {
                        try
                        {
                            fs = new FileStream(@imglists[i], FileMode.Open, FileAccess.Read);
                            imglistec.Images.Add(Image.FromStream(fs));
                        }
                        catch (Exception ex)
                        {
                            wlog.Write(ex.Message);
                            return;
                        }
                    }
                    fs.Close();
                    fs.Dispose();  //释放占用资源
                    GC.Collect();//垃圾回收
                    imgView.View = View.LargeIcon;
                    imgView.LargeImageList = imglistec;
                    if (imglistec.Images.Count > 0)
                    {
                        for (int i = 0; i < imglistec.Images.Count; i++)
                        {
                            imgView.Items.Add("");
                            imgView.Items[i].ImageIndex = i;
                            imgView.Items[i].Tag = i + 1;
                        }
                        zhuanhuannum = imgView.Items.Count;
                    }
                }
                else
                {
                    imgView = new ListView();
                    imglistec = new ImageList();
                    imglists = new List<string>();
                    taxImage.ImageLocation = null;
                    imgView.LargeImageList = null;
                }
            } else if (hsrtlist.Count>0) {
                int tjimgnum = 1;
                int k = xunHuanNum;
                for (k=0;k< showImgNum;k++) {

                    foreach (HighSpeedRailTicket itj in hsrtlist)
                    {
                        if (itj.imgUrl == hsrtlist[k].imgUrl)
                        {
                           
                            break;
                        }
                    }
                    string[] img = hsrtlist[k].imgUrl.Split('/');
                    if (img.Length >= 2)
                    {
                        string imgName = img[img.Length - 1];
                        string batchid = "";
                        if (imgName.Split('_').Length > 1)
                        {
                            batchid = imgName.Split('_')[1];
                        }
                        imglists.Add(newPath + "\\" + batchid + "\\" + imgName);
                    }
                    tjimgnum++;
                }
              
                FileStream fs = null;
                imglistec = new ImageList();
                if (imglists.Count > 0)
                {
                    imglistec.ImageSize = new Size(100, 90);
                    for (int i = 0; i < imglists.Count; i++)
                    {
                        try
                        {
                            fs = new FileStream(@imglists[i], FileMode.Open, FileAccess.Read);
                            imglistec.Images.Add(Image.FromStream(fs));
                        }
                        catch (Exception ex)
                        {
                            wlog.Write(ex.Message);
                            return;
                        }
                    }
                    fs.Close();
                    fs.Dispose();  //释放占用资源
                    GC.Collect();//垃圾回收
                    imgView.View = View.LargeIcon;
                    imgView.LargeImageList = imglistec;
                    if (imglistec.Images.Count > 0)
                    {
                        for (int i = 0; i < imglistec.Images.Count; i++)
                        {
                            imgView.Items.Add("");
                            imgView.Items[i].ImageIndex = i;
                            imgView.Items[i].Tag = i + 1;
                        }
                        zhuanhuannum = imgView.Items.Count;
                    }
                }
                else
                {
                    imgView = new ListView();
                    imglistec = new ImageList();
                    imglists = new List<string>();
                    taxImage.ImageLocation = null;
                    imgView.LargeImageList = null;
                }
            }
        }

        //采购销售筛选
        private void CaiGouXiaoShouShaiXuan(string XiaoGouCompanyName, string XiaoGouCompanyTaxNum)
        {
            IList<InvoiceSonModel> sonpjlist = new List<InvoiceSonModel>();
            List<InvoiiceOcrModel> pjlist = new List<InvoiiceOcrModel>();
            currentXaioFShouFPiaoJuList = new List<InvoiiceOcrModel>();
            InvoiiceOcrModel bp = new InvoiiceOcrModel();
            if (currentPiaoJuList != null)
            {
                if (currentPiaoJuList.Count > 0)
                {
                    for (int i = 0; i < currentPiaoJuList.Count; i++)
                    {
                        if (currentPiaoJuList[i].billtype == 3)
                        {
                            sonpjlist = currentPiaoJuList[i].invoiceOcrSonListSet;
                            if (sonpjlist.Count > 0)
                            {
                                for (int j = 0; j < sonpjlist.Count; j++)
                                {
                                    if (XiaoGouCompanyName == "购方企业名称")
                                    {
                                        if (sonpjlist[j].gftaxnumber == currentPiaoJuList[i].companyTaxnum)
                                        {
                                            bp = new InvoiiceOcrModel();
                                            bp = currentPiaoJuList[i];
                                            pjlist.Add(bp);
                                        }
                                    }
                                    if (XiaoGouCompanyName == "销方企业名称")
                                    {
                                        if (sonpjlist[j].xftaxnumber == currentPiaoJuList[i].companyTaxnum)
                                        {
                                            bp = new InvoiiceOcrModel();
                                            bp = currentPiaoJuList[i];
                                            pjlist.Add(bp);
                                        }
                                    }
                                    if (XiaoGouCompanyName == "代开")
                                    {
                                        bp = new InvoiiceOcrModel();
                                        if (currentPiaoJuList[i].invoiceOcrSonListSet[0].invoiceMark == "代开")
                                        {
                                            bp = currentPiaoJuList[i];
                                            pjlist.Add(bp);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            currentXaioFShouFPiaoJuList = pjlist;
        }
        public void first()
        {
            string apiurl = ApiUrlList.UPDATEREADSTATE;
            string tpresult = "";
            imgclickedinfo = new InvoiiceOcrModel();
            if (imgView.Items.Count > 0)
            {
                int piceNum = 0;
                PicNum.Text = (piceNum + 1).ToString();
                uploadeSucc.Visible = true;
                taxImage.ImageLocation = imglists[0];
                string imgurl = imglists[0];
                imgurl = imgurl.Split('\\')[imgurl.Split('\\').Length - 1];
                if (currentPiaoJuList != null)
                {
                    if (currentPiaoJuList.Count > 0)
                    {
                        for (int i = 0; i < currentPiaoJuList.Count; i++)
                        {
                            if (currentPiaoJuList[i].imgUrl != null)
                            {
                                string image = currentPiaoJuList[i].imgUrl.Split('/')[currentPiaoJuList[i].imgUrl.Split('/').Length - 1];
                                if (image == imgurl)
                                {
                                    imgclickedinfo = currentPiaoJuList[i];
                                    if (currentPiaoJuList[i].invoiceOcrSonListSet.Count > 0)
                                    {
                                        if (currentPiaoJuList[i].invoiceOcrSonListSet[0].readstate != "2")
                                        {
                                            currentPiaoJuList[i].invoiceOcrSonListSet[0].readstate = "1";
                                            string result = RestOrcTool.Post(out tpresult, currentPiaoJuList[i].invoiceOcrSonListSet[0], apiurl);
                                            int index = 0;
                                            imgid = index + 1;
                                            readStateFuZhi(currentPiaoJuList[i], index + 1);
                                            ReadState.BackgroundImage = Resources.looked;
                                        }
                                        if (currentPiaoJuList[i].invoiceOcrSonListSet[0].readstate == "2")
                                        {
                                            int index = 0;
                                            imgid = index + 1;
                                            readStateFuZhi(currentPiaoJuList[i], index + 1);
                                            ReadState.BackgroundImage = Resources.lookeited;
                                        }
                                    }
                                    imageInfos(currentPiaoJuList[i].invoiceOcrSonListSet, currentPiaoJuList[i].invoiceOcrListDetailedSet);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        //图片点击
        private void imgView_Click(object sender, EventArgs e)
        {
            var listview = sender as ListView;
            int piceNum = 0;
            if (listview.SelectedItems!=null) {
                piceNum = listview.SelectedItems[0].ImageIndex;
            }
            PicNum.Text = (piceNum + 1).ToString();
            string apiurl = ApiUrlList.UPDATEREADSTATE;
            string tpresult = "";
            imgclickedinfo = new InvoiiceOcrModel();
            if (imgView.SelectedItems.Count > 0)
            {
                uploadeSucc.Visible = true;
                taxImage.ImageLocation = imglists[imgView.SelectedItems[0].Index];
                string imgurl = imglists[imgView.SelectedItems[0].Index];
                imgurl = imgurl.Split('\\')[imgurl.Split('\\').Length - 1];
            //    textBox1.Text = imgurl;
                if (currentPiaoJuList != null)
                {
                    if (currentPiaoJuList.Count > 0)
                    {
                        for (int i = 0; i < currentPiaoJuList.Count; i++)
                        {
                            if (currentPiaoJuList[i].imgUrl != null)
                            {
                                string image = currentPiaoJuList[i].imgUrl.Split('/')[currentPiaoJuList[i].imgUrl.Split('/').Length - 1];
                                if (image == imgurl)
                                {
                                    imgclickedinfo = currentPiaoJuList[i];
                                    if (currentPiaoJuList[i].invoiceOcrSonListSet.Count > 0)
                                    {
                                        if (currentPiaoJuList[i].invoiceOcrSonListSet[0].readstate != "2")
                                        {
                                            currentPiaoJuList[i].invoiceOcrSonListSet[0].readstate = "1";
                                            string result = RestOrcTool.Post(out tpresult, currentPiaoJuList[i].invoiceOcrSonListSet[0], apiurl);
                                            int index = listview.SelectedItems[0].ImageIndex;
                                            imgid = index + 1;
                                            readStateFuZhi(currentPiaoJuList[i], index + 1);
                                            ReadState.BackgroundImage = Resources.looked;
                                        }
                                        if (currentPiaoJuList[i].invoiceOcrSonListSet[0].readstate == "2")
                                        {
                                            int index = listview.SelectedItems[0].ImageIndex;
                                            imgid = index + 1;
                                            readStateFuZhi(currentPiaoJuList[i], index + 1);
                                            ReadState.BackgroundImage = Resources.lookeited;
                                        }
                                    }
                                    imageInfos(currentPiaoJuList[i].invoiceOcrSonListSet, currentPiaoJuList[i].invoiceOcrListDetailedSet);
                                    break;
                                }
                            }
                        }
                    }
                    if (hsrtTableList.Count>0) {
                        foreach (HighSpeedRailTicket io in hsrtTableList) {
                            string image = io.imgUrl.Split('/')[io.imgUrl.Split('/').Length - 1];
                            if (imgurl == image)
                            {
                                setHSRTList(io);
                                break;
                            }
                        }
                    }
                }
            }
        }
        //给附加读取状态
        private void readStateFuZhi(InvoiiceOcrModel bpms, int imgnum)
        {
            if (bpms != null)
            {
                foreach (PictureBox pb in pbox)
                {
                    if (Convert.ToString(pb.Tag) == Convert.ToString(imgnum))
                    {
                        //this.listimgborder.Controls.Add(pb);
                        pb.Visible = true;
                        pb.BringToFront();
                        if (bpms.invoiceOcrSonListSet.Count > 0)
                        {
                            if (bpms.invoiceOcrSonListSet[0].readstate == "0")
                            {
                                pb.BackgroundImage = Resources.notlook;
                            }
                            else if (bpms.invoiceOcrSonListSet[0].readstate == "1")
                            {
                                pb.BackgroundImage = Resources.looked;
                            }
                            else if (bpms.invoiceOcrSonListSet[0].readstate == "2")
                            {
                                pb.BackgroundImage = Resources.lookeited;
                            }
                        }
                    }
                }
                jiaclose(bpms, imgnum);
            }
        }
        //图片信息
        private void imageInfos(IList<InvoiceSonModel> invoiceOcrSonListSet, IList<invoiceOcrDetailed> invoiOcrDetList)
        {
            dclist = new List<invoiceOcrDetailed>();
            invoiceOcrDetailed dc = new invoiceOcrDetailed();
            currentXuanZhongPiaoJuList = new List<InvoiceSonModel>();
            currentXuanZhongPiaoJuList = invoiceOcrSonListSet;
            if (currentXuanZhongPiaoJuList.Count > 0)
            {
                for (int i = 0; i < invoiceOcrSonListSet.Count; i++)
                {
                    fapiaohm.Text = invoiceOcrSonListSet[i].invoiceNum;
                    kaipiao.Text = invoiceOcrSonListSet[i].invoiceMark;
                    gfgongsi.Text = invoiceOcrSonListSet[i].gfcompanyname;
                    kaipiaoren.Text = invoiceOcrSonListSet[i].kpMan;
                    invoiceType.Text = invoiceOcrSonListSet[i].invoicetype;
                    kaipiaofang.Text = invoiceOcrSonListSet[i].xfcompanyname;
                    jine.Text = invoiceOcrSonListSet[i].totalMoney;
                    string test = invoiceOcrSonListSet[i].detailed;
                    goufangTaxNum.Text = invoiceOcrSonListSet[i].gftaxnumber;
                    money.Text = invoiceOcrSonListSet[i].moneyAmounts;
                    jiashui.Text = invoiceOcrSonListSet[i].taxAmounts;
                    shuilv.Text = invoiceOcrSonListSet[i].taxRate;
                    kptaxnum.Text = invoiceOcrSonListSet[i].xftaxnumber;
                }
                if (invoiOcrDetList == null)
                {
                    invoiOcrDetList = new List<invoiceOcrDetailed>();
                }
                dclist1 = new List<invoiceOcrDetailed>();
                dclist1 = invoiOcrDetList;
                if (invoiOcrDetList.Count >= 2)
                {
                    duojiMingXi.Visible = true;
                }
                else
                {
                    duojiMingXi.Visible = false;
                }
                for (int i=0;i< invoiOcrDetList.Count; i++) {
                    currentXuanZhongPiaoJuMingXiList.Add(invoiOcrDetList[i]);
                }
                
                BindingList<invoiceOcrDetailed> bdlist = new BindingList<invoiceOcrDetailed>(dclist1);
                //mingxiTable.Rows.Clear();
                mingxiTable.DataSource = bdlist;
            }
            else
            {
                fapiaohm.Text = "";
                kaipiao.Text = "";
                gfgongsi.Text = "";
                kaipiaoren.Text = "";
                invoiceType.Text = "";
                kaipiaofang.Text = "";
                jine.Text = "";
                //mingxi.Text = "";
                mingxiTable.DataSource = zhikong;
                goufangTaxNum.Text = "";
                money.Text = "";
                jiashui.Text = "";
                shuilv.Text = "";
                kptaxnum.Text = "";
            }
        }
        private void piaojuXFSFNum(IList<InvoiiceOcrModel> bpmlist)
        {
            int xiaofangnumber = 0;
            int goufangnumber = 0;
            int daikainumber = 0;
            int temp = 0;
            if (bpmlist.Count > 0)
            {
                for (int i = 0; i < bpmlist.Count; i++)
                {
                    if (bpmlist[i].invoiceOcrSonListSet.Count > 0)
                    {
                        for (int j = 0; j < bpmlist[i].invoiceOcrSonListSet.Count; j++)
                        {
                            if (bpmlist[i].billtype==3) {
                                if (bpmlist[i].invoiceOcrSonListSet[j].gfcompanyname == bpmlist[i].companyName)
                                {
                                    goufangnumber++;
                                } else  if (bpmlist[i].invoiceOcrSonListSet[j].xfcompanyname == bpmlist[i].companyName)
                                {
                                    xiaofangnumber++;
                                }else  if (bpmlist[i].invoiceOcrSonListSet[j].invoiceMark == "代开" && bpmlist[i].billtype != -1)
                                {
                                    daikainumber++;
                                }
                                else
                                {
                                    string gfname = bpmlist[i].invoiceOcrSonListSet[j].gfcompanyname;
                                    string xfname = bpmlist[i].invoiceOcrSonListSet[j].gfcompanyname;
                                    string billtype ="" +  bpmlist[i].billtype;
                                    temp++;
                                }
                            }
                        }
                    }
                }
            }
            string s = "" +  temp;
            xiaofangnum.Text = "" + xiaofangnumber;
            caigounum.Text = "" + goufangnumber;
            daikainum.Text = "" + daikainumber;
        }
        //票据数
        private void piaoJuNum(IList<InvoiiceOcrModel> bpmlist)
        {
            int c = 0;
            int j = 0;
            int z = 0;
            int fa = 0;
            int t = 0;
            int fl = 0;
            int d = 0;
            if (bpmlist.Count > 0)
            {
                foreach (InvoiiceOcrModel bpms in bpmlist)
                {
                    if (bpms.billtype == ModelEnum.CUSTOM)
                    {
                        c++;
                    }
                    if (bpms.billtype == ModelEnum.JDCFP)
                    {
                        j++;
                    }
                    if (bpms.billtype == ModelEnum.ZZS_INVOICE)
                    {
                        z++;
                    }
                    if (bpms.billtype == ModelEnum.FAIL)
                    {
                        fa++;
                    }
                    if (bpms.billtype == ModelEnum.TRAIN)
                    {
                        t++;
                    }
                    if (bpms.billtype == ModelEnum.FLY)
                    {
                        fl++;
                    }
                    if (bpms.billtype == ModelEnum.DUIZHANGBILL)
                    {
                        d++;
                    }
                }
                DuiZhangNum.Text = Convert.ToString(d);
                GongZiNum.Text = Convert.ToString(c);
                HuoCheNum.Text = Convert.ToString(t);
                JiDongCheNum.Text = Convert.ToString(j);
                FaPiaoNum.Text = Convert.ToString(z);
                FlyNum.Text = Convert.ToString(fl);
                FeiQiNum.Text = Convert.ToString(fa);
            }
            else
            {
                DuiZhangNum.Text = "0";
                GongZiNum.Text = "0";
                HuoCheNum.Text = "0";
                JiDongCheNum.Text = "0";
                FaPiaoNum.Text = "0";
                FlyNum.Text = "0";
                FeiQiNum.Text = "0";
            }
        }
        //进入各个详情
        //向右按钮
        private void rightbtn_Click(object sender, EventArgs e)
        {
            if (zuizhongList.Count > 9)
            {
                PicNum.Text = "0";
                if (xunHuanNum > 0 && showImgNum > 9)
                {
                    if (showImgNum == zuizhongList.Count || showImgNum == hsrtTableList.Count)
                    {
                        showImgNum = showImgNum - (showImgNum - xunHuanNum);
                        xunHuanNum = xunHuanNum - 9;
                        imgBindList(zuizhongList, new List<HighSpeedRailTicket>());
                        if (hsrtTableList.Count!=0) {
                            imgBindList(new List<InvoiiceOcrModel>(), hsrtTableList);
                        }
                        if (xunHuanNum == 0)
                        {
                            rightbtn.Enabled = false;
                            rightbtn.BackgroundImage = Resources.rightbuttonNoDian;
                        }
                        leftbtn.Enabled = true;
                        leftbtn.BackgroundImage = Resources.leftbutton;
                    }
                    else
                    {
                        xunHuanNum = xunHuanNum - 9;
                        showImgNum = showImgNum - 9;
                        imgBindList(zuizhongList, new List<HighSpeedRailTicket>());
                        leftbtn.Enabled = true;
                        leftbtn.BackgroundImage = Resources.leftbutton;
                    }
                    if (xunHuanNum == 0)
                    {
                        rightbtn.Enabled = false;
                        rightbtn.BackgroundImage = Resources.rightbuttonNoDian;
                    }
                }
                first();
            } else if (hsrtTableList.Count>9) {
                PicNum.Text = "0";
                if (xunHuanNum > 0 && showImgNum > 9)
                {
                    if (showImgNum == hsrtTableList.Count)
                    {
                        showImgNum = showImgNum - (showImgNum - xunHuanNum);
                        xunHuanNum = xunHuanNum - 9;
                        imgBindList(new List<InvoiiceOcrModel>(), hsrtTableList);
                        if (xunHuanNum == 0)
                        {
                            rightbtn.Enabled = false;
                            rightbtn.BackgroundImage = Resources.rightbuttonNoDian;
                        }
                        leftbtn.Enabled = true;
                        leftbtn.BackgroundImage = Resources.leftbutton;
                    }
                    else
                    {
                        xunHuanNum = xunHuanNum - 9;
                        showImgNum = showImgNum - 9;
                        imgBindList(new List<InvoiiceOcrModel>(), hsrtTableList);
                        leftbtn.Enabled = true;
                        leftbtn.BackgroundImage = Resources.leftbutton;
                    }
                    if (xunHuanNum == 0)
                    {
                        rightbtn.Enabled = false;
                        rightbtn.BackgroundImage = Resources.rightbuttonNoDian;
                    }
                }
                first();
            }
        }
        //向左按钮
        private void leftbtn_Click(object sender, EventArgs e)
        {
            if (zuizhongList.Count > 9)
            {
                PicNum.Text = "0";
                if (xunHuanNum < zuizhongList.Count - 9 && showImgNum < zuizhongList.Count - 9)
                {
                    xunHuanNum = xunHuanNum + 9;
                    showImgNum = showImgNum + 9;
                    imgBindList(zuizhongList, new List<HighSpeedRailTicket>());
                    rightbtn.Enabled = true;
                    rightbtn.BackgroundImage = Resources.rightbutton;
                }
                else if ((zuizhongList.Count - showImgNum) < 9 && (zuizhongList.Count - showImgNum) > 0)
                {
                    xunHuanNum = xunHuanNum + 9;
                    showImgNum = zuizhongList.Count;
                    hidenTuBiao();
                    imgBindList(zuizhongList, new List<HighSpeedRailTicket>());
                    leftbtn.Enabled = false;
                    leftbtn.BackgroundImage = Resources.leftbuttonNoDian;
                    rightbtn.Enabled = true;
                    rightbtn.BackgroundImage = Resources.rightbutton;
                }
                first();
            }
            else if(hsrtTableList.Count>9)
            {
                PicNum.Text = "0";
                if (xunHuanNum < hsrtTableList.Count - 9 && showImgNum <= hsrtTableList.Count - 9)
                {
                    xunHuanNum = xunHuanNum + 9;
                    showImgNum = showImgNum + 9;
                    imgBindList(new List<InvoiiceOcrModel>(), hsrtTableList);
                    rightbtn.Enabled = true;
                    rightbtn.BackgroundImage = Resources.rightbutton;
                }
                else if ((hsrtTableList.Count - showImgNum) <= 9 && (hsrtTableList.Count - showImgNum) > 0)
                {
                    xunHuanNum = xunHuanNum + 9;
                    showImgNum = hsrtTableList.Count;
                    hidenTuBiao();
                    imgBindList(new List<InvoiiceOcrModel>(), hsrtTableList);
                    leftbtn.Enabled = false;
                    leftbtn.BackgroundImage = Resources.leftbuttonNoDian;
                    rightbtn.Enabled = true;
                    rightbtn.BackgroundImage = Resources.rightbutton;
                }
                first();
            }
        }
        //得总数据
        private void getPiaoJuAllClick()
        {
            bpmlist = new List<InvoiiceOcrModel>();
            BatchInfo bm = new BatchInfo();
            string tpresult = "";
            string apiurl2 = ApiUrlList.GETDATAALL;
            string result = "";
            try
            {
                // bm.addTime = DateTime.Today;
                result = RestDataTool.Post2(out tpresult, bm, apiurl2, out bpmlist);
            }
            catch (Exception es)
            {
                wlog.Write(es.Message);
                return;
            }
            if (bpmlist.Count > 0)
            {
                currentPiaoJuList = new List<InvoiiceOcrModel>();
                currentPiaoJuList = bpmlist;
            }
            else
            {
                currentPiaoJuList = new List<InvoiiceOcrModel>();
            }
        }
        //获取公司库
        private void getCompanyAllData()
        {
            string tpresult = "";
            string apiurl2 = ApiUrlList.GETCOMPANYALL;
            string result = "";
            BatchInfo bm = new BatchInfo();
            List<BatchInfo> bilist = new List<BatchInfo>();
            try
            {
                bm.batchtimes = currentDeclareDate;
                result = RestDataTool.Post(out tpresult, bm, apiurl2, out bilist);
                if (bilist.Count > 0)
                {
                    companyAll = bilist;
                }
            }
            catch (Exception es)
            {
                wlog.Write(es.Message);
                return;
            }
        }
        //清空票据信息
        private void clearInvoiceInfo()
        {
            fapiaohm.Text = "";
            kaipiao.Text = "";
            gfgongsi.Text = "";
            kaipiaoren.Text = "";
            invoiceType.Text = "";
            kaipiaofang.Text = "";
            jine.Text = "";
            // mingxi.Text = "";
            mingxiTable.DataSource = zhikong;
            goufangTaxNum.Text = "";
            money.Text = "";
            jiashui.Text = "";
            kptaxnum.Text = "";
            shuilv.Text = "";
        }
        //刷新
        private void label1_Click_1(object sender, EventArgs e)
        {
            wlog.Write("刷新界面");
            //xiangqing.Rows.Clear();
            Form6_Load(sender, e);
        }
        //清除数据
        private void ClearDate()
        {
            currentXuanZhongPiaoJuList = new List<InvoiceSonModel>();
            companysx.AutoGenerateColumns = false;
            bpmlist = new List<InvoiiceOcrModel>();
            currentCompanyName = null;
            currentDeclareDate = null;
            currentSeachText = null;
            currentSeachPiaoJuType = -100;
            currentDeclareDate = null;
            currentCompanyName = null;
            currentXaioFShouFPiaoJuList = null;
            ButtonDown = null;
            ButtonDowns = null;
            companyAll = new List<BatchInfo>();
            currentPiaoJuList = new List<InvoiiceOcrModel>();
            CompanyNameBT.Text = "";
        }
        private void allbutenhuifu()
        {
            foreach (Button bt in btnsTypeXS)
            {
                bt.BackColor = Color.MintCream;
            }
        }
        //设置类别按钮颜色
        private void SetPiaoJuTypeBtnColor(Button btn)
        {
            foreach (Button bt in btnsTypeXS)
            {
                if (bt.Tag == btn.Tag)
                {
                    bt.BackColor = Color.Silver;
                }
                else
                {
                    bt.BackColor = Color.MintCream;
                    setkongjianWith();
                }
            }
        }
        private void mingxi_TextChanged(object sender, EventArgs e)
        {
        }
        //修改
        private void kaipiao_Leave(object sender, EventArgs e)
        {

        }

        private void updatePIaoJuCmpany(string tpresult, string apiurlupdatemainCompany)
        {
                try
                {
                    string result = RestOrcTool.Post(out tpresult, imgclickedinfo, apiurlupdatemainCompany);
                }
                catch (Exception ex)
                {
                    WsdLogger.yxlog("error", "更新公司失败" + ex.Message);
                }
        }

        private bool setCompanyName(string biduigongsi,string value)
        {
            if (imgclickedinfo.companyName == biduigongsi)
            {
                if (value != imgclickedinfo.companyName)
                {
                    //更新主表公司
                    imgclickedinfo.companyName = value;
                    return true;
                }
            }
            return false;
        }
        private bool setCompanyTaxNum(string biduigongsi, string value)
        {
            if (imgclickedinfo.companyTaxnum == biduigongsi)
            {
                if (value != imgclickedinfo.companyTaxnum)
                {
                    //更新主表公司
                    imgclickedinfo.companyTaxnum = value;
                    return true;
                }
            }
            return false;
        }

        private void setBilltype(string apiurl)
        {
            string tpresult = "";
            imgclickedinfo.billtype = 3;
            imgclickedinfo.billtypeDesc = "增值税专用发票模板";
            imgclickedinfo.state = 0;
            imgclickedinfo.stateDesc = "未启用";
            //修改主表状态
            try
            {
                string result = RestOrcTool.Post(out tpresult, imgclickedinfo, apiurl);
            }
            catch (Exception ex)
            {
                WsdLogger.yxlog("error", "更新状态失败" + ex.Message);
            }
        }

        //判断是否需要更改
        public bool isedited(string name, string value)
        {
            if (name == "kaipiao")
            {
                if (value == currentXuanZhongPiaoJuList[0].invoiceMark)
                {
                    return false;
                }
            }
            else if (name == "fapiaohm")
            {
                if (value == currentXuanZhongPiaoJuList[0].invoiceNum)
                {
                    return false;
                }
            }
            else if (name == "gfgongsi")
            {
                if (value == currentXuanZhongPiaoJuList[0].gfcompanyname)
                {
                    return false;
                }
            }
            else if (name == "kaipiaoren")
            {
                if (value == currentXuanZhongPiaoJuList[0].kpMan)
                {
                    return false;
                }
            }
            else if (name == "invoiceType")
            {
                if (value == currentXuanZhongPiaoJuList[0].invoicetype)
                {
                    return false;
                }
            }
            else if (name == "kaipiaofang")
            {
                if (value == currentXuanZhongPiaoJuList[0].xfcompanyname)
                {
                    return false;
                }
            }
            else if (name == "jine")
            {
                if (value == currentXuanZhongPiaoJuList[0].totalMoney)
                {
                    return false;
                }
            }
            else if (name == "mingxi")
            {
                if (value == currentXuanZhongPiaoJuList[0].detailed)
                {
                    return false;
                }
            }
            else if (name == "goufangTaxNum")
            {
                if (value == currentXuanZhongPiaoJuList[0].gftaxnumber)
                {
                    return false;
                }
            }
            else if (name == "money")
            {
                if (value == currentXuanZhongPiaoJuList[0].moneyAmounts)
                {
                    return false;
                }
            }
            else if (name == "jiashui")
            {
                if (value == currentXuanZhongPiaoJuList[0].taxAmounts)
                {
                    return false;
                }
            }
            else if (name == "shuilv")
            {
                if (value == currentXuanZhongPiaoJuList[0].taxRate)
                {
                    return false;
                }
            }
            else if (name == "kptaxnum")
            {
                if (value == currentXuanZhongPiaoJuList[0].xftaxnumber)
                {
                    return false;
                }
            }
            return true;
        }
        private void CompanyNameEnd_Click(object sender, EventArgs e)
        {
        }
        private void hidenTuBiao()
        {
            foreach (PictureBox pb in pbox)
            {
                pb.Visible = false;
            }
            foreach (PictureBox dpb in delepbox)
            {
                dpb.Visible = false;
            }
        }
        //打开模态框
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Hide();
            hidenTuBiao();
            cg.compGroupCR(currentDeclareDate, currentCompanyName);
            cg.Show();
        }
        //删除票据
        private void close_Click(object sender, EventArgs e)
        {
            ButtonDowns = "转换";
            PictureBox pnox = sender as PictureBox;
            InvoiiceOcrModel deleion = new InvoiiceOcrModel();
            deleion.id = 0;
            string apiUrl = ApiUrlList.DELETEPAIOJU;
            string tempt = "";
            if (zuizhongList.Count > 0)
            {
                for (int i = 0; i < currentPiaoJuList.Count; i++)
                {
                    if (Convert.ToString(pnox.Tag) == Convert.ToString(currentPiaoJuList[i].id))
                    {
                        deleion = currentPiaoJuList[i];
                        currentPiaoJuList.Remove(currentPiaoJuList[i]);
                    }
                }
            }
            try
            {
                if (deleion.id != 0)
                {
                    var result = RestOrcTool.Post(out tempt, deleion, apiUrl);
                    showImgNum = showImgNum - 1;
                    xunHuanNum = 0;
                    BindPiaoJuList();
                }
            }
            catch (Exception ex)
            {
                wlog.Write("删除票据错误信息" + ex.Message);
            }
        }
        //获取MAC地址
        private string getHostIpName()
        {
            string mac = "";
            ManagementClass mc;
            mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if (mo["IPEnabled"].ToString() == "True")
                    mac = mo["MacAddress"].ToString();
            }
            return mac;
        }
        private void jiaclose(InvoiiceOcrModel bpms, int imgnum)
        {
            if (imgnum == 1)
            {
                close1.Visible = true;
                if (bpms.invoiceOcrSonListSet.Count > 0)
                {
                    close1.Tag = bpms.id;//主表id
                }
                close1.BackgroundImage = Resources.CLOSE;
                close1.BringToFront();
            }
            if (imgnum == 2)
            {
                close2.Visible = true;
                if (bpms.invoiceOcrSonListSet.Count > 0)
                {
                    close2.Tag = bpms.id;//主表id
                }
                close2.BackgroundImage = Resources.CLOSE;
                close2.BringToFront();
            }
            if (imgnum == 3)
            {
                close3.Visible = true;
                if (bpms.invoiceOcrSonListSet.Count > 0)
                {
                    close3.Tag = bpms.id;//主表id
                }
                close3.BackgroundImage = Resources.CLOSE;
                close3.BringToFront();
            }
            if (imgnum == 4)
            {
                close4.Visible = true;
                if (bpms.invoiceOcrSonListSet.Count > 0)
                {
                    close4.Tag = bpms.id;//主表id
                }
                close4.BackgroundImage = Resources.CLOSE;
                close4.BringToFront();
            }
            if (imgnum == 5)
            {
                close5.Visible = true;
                if (bpms.invoiceOcrSonListSet.Count > 0)
                {
                    close5.Tag = bpms.id;//主表id
                }
                close5.BackgroundImage = Resources.CLOSE;
                close5.BringToFront();
            }
            if (imgnum == 6)
            {
                close6.Visible = true;
                if (bpms.invoiceOcrSonListSet.Count > 0)
                {
                    close6.Tag = bpms.id;//主表id
                }
                close6.BackgroundImage = Resources.CLOSE;
                close6.BringToFront();
            }
            if (imgnum == 7)
            {
                close7.Visible = true;
                if (bpms.invoiceOcrSonListSet.Count > 0)
                {
                    close7.Tag = bpms.id;//主表id
                }
                close7.BackgroundImage = Resources.CLOSE;
                close7.BringToFront();
            }
            if (imgnum == 8)
            {
                close8.Visible = true;
                if (bpms.invoiceOcrSonListSet.Count > 0)
                {
                    close8.Tag = bpms.id;//主表id
                }
                close8.BackgroundImage = Resources.CLOSE;
                close8.BringToFront();
            }
            if (imgnum == 9)
            {
                close9.Visible = true;
                if (bpms.invoiceOcrSonListSet.Count > 0)
                {
                    close9.Tag = bpms.id;//主表id
                }
                close9.BackgroundImage = Resources.CLOSE;
                close9.BringToFront();
            }
        }
        //移入三个点
        private void duojiMingXi_MouseMove(object sender, MouseEventArgs e)
        {
            duojiMingXi.BackgroundImage = Resources.sangedianliang;
        }
        //移除三个点
        private void duojiMingXi_MouseLeave(object sender, EventArgs e)
        {
            duojiMingXi.BackgroundImage = Resources.sangedian;
        }
        private void duojiMingXi_Click(object sender, EventArgs e)
        {
            if (dclist1.Count > 0)
            {
                MingXiInfo mxi = new MingXiInfo(dclist1, currentPiaoJuList, this);
                mxi.Show();
            }
        }
        public void getPiaoJuMingXi(IList<InvoiiceOcrModel> currentMingXiPiaoJuList, bool gaiBian, IList<invoiceOcrDetailed> invoiOcrDetList)
        {
            currentPiaoJuList = currentMingXiPiaoJuList;
            if (gaiBian)
            {
                InvoiiceOcrModel bp = new InvoiiceOcrModel();
                currentXuanZhongPiaoJuList[0].readstate = "2";
                bp.invoiceOcrSonListSet = currentXuanZhongPiaoJuList;
                readStateFuZhi(bp, imgid);
                BindingList<invoiceOcrDetailed> bdlist = new BindingList<invoiceOcrDetailed>(invoiOcrDetList);
                mingxiTable.DataSource = bdlist;
            }
        }
        private void PicNum_Click(object sender, EventArgs e)
        {
        }
        private void mingxiTable_Leave(object sender, EventArgs e)
        {
        }
        //修改明细
        private void mingxiTable_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            var imingxi = sender as DataGridView;
            string temp = "";
            if (e.RowIndex != -1)
            {
                string strcolumn = imingxi.Columns[e.ColumnIndex].DataPropertyName;//获取列标题
                string value = imingxi.CurrentCell.Value.ToString();//获取当前点击的活动单元格的值
                IList<invoiceOcrDetailed> list = currentXuanZhongPiaoJuMingXiList;
                getMingXiData(strcolumn, value);
                string apiurl = ApiUrlList.UPDATEDETAILED;//更新明细
                try
                {
                    var result = RestOrcTool.Post(out temp, dclist1[0], apiurl);
                }
                catch (Exception ex)
                {
                    wlog.Write("更新明细表出错：" + ex.Message);
                }
                InvoiiceOcrModel bp = new InvoiiceOcrModel();
                currentXuanZhongPiaoJuList[0].readstate = "2";
                bp.invoiceOcrSonListSet = currentXuanZhongPiaoJuList;
                readStateFuZhi(bp, imgid);
                for (int j = 0; j < currentPiaoJuList.Count; j++)
                {
                    for (int i = 0; i < currentPiaoJuList[j].invoiceOcrListDetailedSet.Count; i++)
                    {
                        if (currentPiaoJuList[j].invoiceOcrListDetailedSet[i].id == dclist1[0].id)
                        {
                            currentPiaoJuList[j].invoiceOcrListDetailedSet[i] = dclist1[0];
                        }
                    }
                }
            }
        }
        private void getMingXiData(string strcolumn, string value)
        {
            if (strcolumn == "productName")
            {
                dclist1[0].productName = value;
            }
            if (strcolumn == "mxMoney")
            {
                dclist1[0].moneyAmount = value;
            }
            if (strcolumn == "mxTaxlv")
            {
                dclist1[0].detaileTaxRate = value;
            }
            if (strcolumn == "mxTaxMoney")
            {
                dclist1[0].taxAmount = value;
            }
        }
        private List<InvoiceOcrTaxtjtableMx> getTongjiTableMingXiData(string strcolumn, string value,string id)
        {
            List<InvoiceOcrTaxtjtableMx> endlist = new List<InvoiceOcrTaxtjtableMx>();
            for (int i=0;i< currentcliicktongjitabledata.Count; i++) {
                if (id == Convert.ToString(currentcliicktongjitabledata[i].id)) {
                    if (strcolumn == "tjprojectName")
                    {
                        currentcliicktongjitabledata[i].tjprojectName = value;
                    }
                    if (strcolumn == "tjheji")
                    {
                        currentcliicktongjitabledata[i].tjheji = value;
                    }
                    if (strcolumn == "seventeenPercent")
                    {
                        currentcliicktongjitabledata[i].seventeenPercent = value;
                    }
                    if (strcolumn == "sixPercent")
                    {
                        currentcliicktongjitabledata[i].sixPercent = value;
                    }
                    if (strcolumn == "threePercent")
                    {
                        currentcliicktongjitabledata[i].threePercent = value;
                    }
                    if (strcolumn == "fourPercent")
                    {
                        currentcliicktongjitabledata[i].fourPercent = value;
                    }
                    if (strcolumn == "tenPercent")
                    {
                        currentcliicktongjitabledata[i].tenPercent = value;
                    }
                    if (strcolumn == "threeteenPercent")
                    {
                        currentcliicktongjitabledata[i].threeteenPercent = value;
                    }
                    if (strcolumn == "eightteenPercent")
                    {
                        currentcliicktongjitabledata[i].eightteenPercent = value;
                    }
                    if (strcolumn == "qita")
                    {
                        currentcliicktongjitabledata[i].qita = value;
                    }
                    if (strcolumn == "sixteenPercent")
                    {
                        currentcliicktongjitabledata[i].sixteenPercent = value;
                    }
                    endlist.Add(currentcliicktongjitabledata[i]);
                }
            }
            return endlist;
        }
        private string getMac()
        {
            string macaddress = AppDomain.CurrentDomain.BaseDirectory + "mac.txt";
            string readmac = "";
            if (File.Exists(macaddress))
            {
                string[] line = File.ReadAllLines(macaddress);
                if (line.Length > 0)
                {
                    readmac = line[0];
                }
                else
                {
                    readmac = getHostIpName();//获取
                }
            }
            else
            {
                readmac = getHostIpName();//获取
            }
            return readmac;
        }
        //关闭窗口
        private void AdminJM_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (isnPross)
                {
                    prosses.Kill();
                }
            }
            catch (Exception ex)
            {
                return;
            }
            try
            {
                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                return;
            }
        }
        public void textChange(string text)
        {
            SaoMiaoYiB.Text = text;
        }
        #region 窗体缩放     
        private void AdminJM_SizeChanged(object sender, EventArgs e)
        {
            //if (autoAdaptSize != null)
            //{
            //    autoAdaptSize.FormSizeChanged();
            //}
        }
        #endregion

        private void invoiceSonModelBindingSource1_CurrentChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }
        //修改统计表
        private void tongjilisttable_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            //1.1得到统计表修改后的数据
            var currentHang = sender as DataGridView;
            string temp = "";
            //2.2传到服务器进行修改currentcliicktongjitabledata
            if (e.RowIndex != -1)
            {
                string strcolumn = currentHang.Columns[e.ColumnIndex].DataPropertyName;//获取列标题
                string value = currentHang.CurrentCell.Value.ToString();//获取当前点击的活动单元格的值
                string strrow = currentHang.Rows[e.RowIndex].Cells[0].Value.ToString();//获取焦点触发行的第一个值
                List<InvoiceOcrTaxtjtableMx> endlist = getTongjiTableMingXiData(strcolumn, value, strrow);
                string apiurl = ApiUrlList.UPDATETONGJITABLEINFO;//更新明细
                try
                {
                    var result = RestOrcTool.Post(out temp, endlist[0], apiurl);
                }
                catch (Exception ex)
                {
                    wlog.Write("更新统计明细表出错：" + ex.Message);
                }
                for (int j = 0; j < iotable.Count; j++)
                {
                    for (int i = 0; i < iotable[j].invoiceOcrTaxtjtableMxSet.Count; i++)
                    {
                        if (iotable[j].invoiceOcrTaxtjtableMxSet[i].id == currentcliicktongjitabledata[0].id)
                        {
                            iotable[j].invoiceOcrTaxtjtableMxSet[i] = currentcliicktongjitabledata[0];
                        }
                    }
                }
            }
        }
        //修改主表信息
        private void tjcompanyname_Leave(object sender, EventArgs e)
        {
            var text = sender as TextBox;
            string temp = "";
            string apiurl = ApiUrlList.UPDATETONGJITABLEMAIN;//更新明细
            if (currentclickTableMain.Count > 0)
            {
                if (text.Name == "tjcompanyname")
                {
                    if (text.Text != currentclickTableMain[0].tjcompanyName)
                    {
                        currentclickTableMain[0].tjcompanyName = text.Text;
                    }
                }
                else if (text.Name == "tjtaxnumber")
                {
                    if (text.Text != currentclickTableMain[0].tjcompanyTaxnum)
                    {
                        currentclickTableMain[0].tjcompanyTaxnum = text.Text;
                    }
                }
                else if (text.Name == "tjszhibiaodate")
                {
                    if (text.Text != currentclickTableMain[0].zhibiaoDate)
                    {
                        currentclickTableMain[0].zhibiaoDate = text.Text;
                    }
                }
                try
                {
                    var result = RestOrcTool.Post(out temp, currentclickTableMain[0], apiurl);
                }
                catch (Exception ex)
                {
                    wlog.Write("更新明细表出错：" + ex.Message);
                }
                for (int i=0;i< iotable.Count; i++) {
                    if (iotable[i].id== currentclickTableMain[0].id) {
                        iotable[i].tjcompanyName = currentclickTableMain[0].tjcompanyName;
                        iotable[i].tjcompanyTaxnum = currentclickTableMain[0].tjcompanyTaxnum;
                        iotable[i].zhibiaoDate = currentclickTableMain[0].zhibiaoDate;
                    }
                }

            }

        }

        private void tongjilisttable_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void SaoMiaoYiB_Click(object sender, EventArgs e)
        {

        }

        private void tongjinum_Click(object sender, EventArgs e)
        {

        }
    }
}